<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Custom Feed and Entry Classes - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.feed.custom-feed.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.feed.custom-feed.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.feed.modifying-feed.html">Modifying Feed and Entry structures</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.feed.html">Zend_Feed</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.feed.reader.html">Zend_Feed_Reader</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.feed.custom-feed" class="section"><div class="info"><h1 class="title">Custom Feed and Entry Classes</h1></div>
    

    <p class="para">
        Finally, you can extend the <span class="classname">Zend_Feed</span> classes if you&#039;d like to
        provide your own format or niceties like automatic handling of elements that should go into
        a custom namespace.
    </p>

    <p class="para">
        Here is an example of a custom Atom entry class that handles its own
        <em class="emphasis">myns:</em> namespace entries. Note that it also makes the
         <span class="methodname">registerNamespace()</span> call for you, so the end user doesn&#039;t need to
        worry about namespaces at all.
    </p>

    <div class="example" id="zend.feed.custom-feed.example.extending"><div class="info"><p><b>Example #1 Extending the Atom Entry Class with Custom Namespaces</b></p></div>
        

        <pre class="programlisting brush: php">
/**
 * The custom entry class automatically knows the feed URI (optional) and
 * can automatically add extra namespaces.
 */
class MyEntry extends Zend_Feed_Entry_Atom
{

    public function __construct($uri = &#039;http://www.example.com/myfeed/&#039;,
                                $xml = null)
    {
        parent::__construct($uri, $xml);

        Zend_Feed::registerNamespace(&#039;myns&#039;,
                                     &#039;http://www.example.com/myns/1.0&#039;);
    }

    public function __get($var)
    {
        switch ($var) {
            case &#039;myUpdated&#039;:
                // Translate myUpdated to myns:updated.
                return parent::__get(&#039;myns:updated&#039;);

            default:
                return parent::__get($var);
            }
    }

    public function __set($var, $value)
    {
        switch ($var) {
            case &#039;myUpdated&#039;:
                // Translate myUpdated to myns:updated.
                parent::__set(&#039;myns:updated&#039;, $value);
                break;

            default:
                parent::__set($var, $value);
        }
    }

    public function __call($var, $unused)
    {
        switch ($var) {
            case &#039;myUpdated&#039;:
                // Translate myUpdated to myns:updated.
                return parent::__call(&#039;myns:updated&#039;, $unused);

            default:
                return parent::__call($var, $unused);
        }
    }
}
</pre>


        <div class="example-contents"><p>
            Then to use this class, you&#039;d just instantiate it directly and set the
            <span class="property">myUpdated</span> property:
        </p></div>

        <pre class="programlisting brush: php">
$entry = new MyEntry();
$entry-&gt;myUpdated = &#039;2005-04-19T15:30&#039;;

// method-style call is handled by __call function
$entry-&gt;myUpdated();
// property-style call is handled by __get function
$entry-&gt;myUpdated;
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.feed.modifying-feed.html">Modifying Feed and Entry structures</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.feed.html">Zend_Feed</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.feed.reader.html">Zend_Feed_Reader</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.feed.html">Zend_Feed</a></li>
  <li><a href="zend.feed.introduction.html">Introduction</a></li>
  <li><a href="zend.feed.importing.html">Importing Feeds</a></li>
  <li><a href="zend.feed.findFeeds.html">Retrieving Feeds from Web Pages</a></li>
  <li><a href="zend.feed.consuming-rss.html">Consuming an RSS Feed</a></li>
  <li><a href="zend.feed.consuming-atom.html">Consuming an Atom Feed</a></li>
  <li><a href="zend.feed.consuming-atom-single-entry.html">Consuming a Single Atom Entry</a></li>
  <li><a href="zend.feed.modifying-feed.html">Modifying Feed and Entry structures</a></li>
  <li class="active"><a href="zend.feed.custom-feed.html">Custom Feed and Entry Classes</a></li>
  <li><a href="zend.feed.reader.html">Zend_Feed_Reader</a></li>
  <li><a href="zend.feed.writer.html">Zend_Feed_Writer</a></li>
  <li><a href="zend.feed.pubsubhubbub.introduction.html">Zend_Feed_Pubsubhubbub</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>